package app;

import datastructure.Instance;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

public class Drawgraph extends JFrame {
    int divide = 0;
    int numofCustomer = 0;
    int numofPFC = 0;
    int numofTask = 0;

    double a = 0;
    double b = 0;
    double Len = 0;

    double c1 = 0;
    double c2 = 0;
    double miu = 0;
    double Fi = 0;
    double Fm = 0;
    double[] delta;

    double[][] distanceMatrix;
    int[][] ODdemand;

    double[][] coordinateofPFC;
    double[][] coordinateofCustomer;

    int experimentnumber = 0;
    String time;

    public Drawgraph(Instance instance, int experimentnumber, String time) {
        this.numofPFC = instance.numofPFC;
        this.divide = instance.divide;
        this.numofCustomer = instance.numofCustomer;
        this.numofTask = instance.numofTask;
        this.a = instance.a;
        this.b = instance.b;
        this.Len = instance.Len;
        this.c1 = instance.c1;
        this.c2 = instance.c2;
        this.miu = instance.miu;
        this.Fi = instance.Fi;
        this.Fm = instance.Fm;
        this.delta = instance.delta;
        this.ODdemand = instance.ODdemand;
        this.distanceMatrix = instance.distanceMatrix;
        this.coordinateofPFC = instance.coordinateofPFC;
        this.coordinateofCustomer = instance.coordinateofCustomer;

        this.experimentnumber = experimentnumber;
        this.time = time;
    }

    public void draw() {

        BufferedImage image = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.createGraphics();

        try {

            g.setColor(new Color(0xF5F5F5));
            g.setColor(Color.white);
            g.fillRect(0, 0, 600, 600);
            g.setColor(Color.black);
            g.drawRect(50, 50, 500, 500);

            int rr = (int) (Math.random() * 255);
            int gg = (int) (Math.random() * 255);
            int bb = (int) (Math.random() * 255);
            g.setColor(new Color(rr, gg, bb));

            for (int i = 0; i < numofCustomer; i++) {
                g.setColor(Color.cyan);
                g.fillOval((int) (coordinateofCustomer[i][0] - 2 + 50), (int) (coordinateofCustomer[i][1] - 2 + 50), 4, 4);
                g.drawString("C" + (i + 1), (int) (coordinateofCustomer[i][0] + 4 + 50), (int) (coordinateofCustomer[i][1] + 4 + 50));

            }

            for (int i = 0; i < numofPFC; i++) {
                g.setColor(Color.cyan);
                g.fillOval((int) (coordinateofPFC[i][0] - 2 + 50), (int) (coordinateofPFC[i][1] - 2 + 50), 4, 4);
                g.drawString("P" + (i + 1), (int) (coordinateofPFC[i][0] + 4 + 50), (int) (coordinateofPFC[i][1] + 12 + 50));

            }


            ImageIO.write(image, "png", new File("model/pic model/" + divide + ".png"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}